package com.woniuxy.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.woniuxy.annotations.RequireRole;
import com.woniuxy.entity.utils.ResponseEntity;
import com.woniuxy.service.OrderService;
import com.woniuxy.service.OrderServiceByProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@RefreshScope
public class OrderController {

    @Value("${woniu.config}")
    private String myConfig;

    @Autowired
    OrderService orderService;

    @Autowired
    OrderServiceByProduct orderServiceByProduct;

    @PostMapping("/{pid}/{num}")
    @RequireRole(role={"order::add"})
    public ResponseEntity generateOrder(@PathVariable Integer pid,@PathVariable Integer num){
        return orderService.generateOrder(pid,num);
    }

    @GetMapping("/{name}/{minPrice}/{maxPrice}")
    public ResponseEntity findProductList(@PathVariable String name,@PathVariable double minPrice,@PathVariable double maxPrice){
        return orderServiceByProduct.findProductList(name,minPrice,maxPrice);
    }

    @SentinelResource(value="yuema")
    @GetMapping("/showConfig")
    public ResponseEntity showConfig(){
        return new ResponseEntity(myConfig);

    }
}